// 把数据渲染到html代码中.log
const Vue = require('vue')
const server = require('express')()
const renderer = require('vue-server-renderer').createRenderer()

server.get('*', (req, res) => {
	const app = new Vue({
		data: {
			url: req.url
		},
		template: `<div>访问的URL是: {{ url }} </div>`
	})
	
	renderer.renderToString(app, (err, html) => {
		if (err) {
			res.status(500).end('Internal Server Error')
			return
		}
		res.end(`
			<!DOCTYPE html>
			<html>
				<head><title>Hello</title></head>
				<body>${html}</body>
		`)
	})
})

server.listen(8080)